javascript removeChild(this) from input[type="submit"] onclick breaks future use of form.submit() un

Posted by maximumduncan on Stack Overflow See other posts from Stack Overflow or by maximumduncan
Published on 2010-03-10T12:04:35Z Indexed on 2010/04/10 19:43 UTC
Read the original article Hit count: 565

Filed under:
|
|
|

I have come across some strange behaviour, and I'm assuming a bug in firefox, when removing a input submit element from the DOM from within the click event.

The following code reproduces the issue:

<form name="test_form">
<input type="submit" value="remove me" onclick="this.parentNode.removeChild(this);" />
<input type="submit" value="submit normally" />
<input type="button" value="submit via js" onclick="document.test_form.submit();" />
</form>

To reproduce:

  • Click "remove me"
  • Click "submit via js". Note that the form does not get submitted, this is the problem.
  • Click "submit normally". Note that the form still gets submitted normally.

It appears that, under Firefox, if you remove a submit button from within the click event it puts the form in an invalid state so that any future calls to form.submit() are simply ignored. But it is a javascript-specific issue as normal submit buttons within this form still function fine.

To be honest, this is such a simple example of this issue that I was expecting the internet to be awash with other people exeriencing it, but so far searching has yealded nothing useful.

Has anyone else experienced this and if so, did you get to the bottom of it?

Many thanks

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about dom